/**
 * 毛文科
 */
/**php时间转化成js时间
 * Created by Administrator on 2018\8\21 0017.
 */
function timeToStr($time,$true){
    if(!$time){
        return '';
    }
    var $obj = new Date($time*1000);
    var $nian=$obj.getFullYear();
    var $yue = ($obj.getMonth())+1;
    if($yue<10){
        $yue = '0'+$yue;
    }
    var $day = $obj.getDate();
    if($day<10){
        $day = '0'+$day;
    }
    if($true==true){
        var $hours = $obj.getHours();
        if($hours<10){
            $hours = '0'+$hours;
        }
        var $minutes = $obj.getMinutes();
        if($minutes<10){
            $minutes = '0'+$minutes;
        }
        var $seconds = $obj.getSeconds();
        if($seconds<10){
            $seconds = '0'+$seconds;
        }
        var $str = $nian+'-'+$yue+'-'+$day+' '+$hours+':'+$minutes+':'+$seconds;
    }else{
        var $str = $nian+'-'+$yue+'-'+$day;
    }
    return $str;
}
/**
 * ajax上传文件
 * @param string $id 要上传的form表单的对象
 * @param string $url 要上传的url地址
 * @returns {*}
 */
function ajaxs($id,$url,$success,$error){
    if($id.get(0).tagName=='FORM'){
        $id.attr('enctype','multipart/form-data');
        var $data=new FormData($id[0]);
        $.ajax({
            url: $url,
            type: 'POST',
            cache: false,
            async:false,
            data: $data,
            processData: false,
            contentType: false,
            success:$success,
            error:$error
        });
    }else{
        var $formdata=new FormData();
        $formdata.append('file',$id.get(0).files[0]);
        var $str;
        $.ajax({
            url: $url,
            type: 'POST',
            cache: false,
            async:false,
            data: $formdata,
            processData: false,
            contentType: false,
            success:$success,
            error:$error
        });
    }
}
/**
 * 检测是否为手机号
 * @param string  $phone 传入要检测的号码
 * @returns {boolean} 是传回true不是传回false
 */
function isPhone($phone){
    var $phonezz=/^1[345789][0-9]{9}$/;
    if($phonezz.test($phone)){
        return true;
    }else{
        return false;
    }
}
/**
 * 检测是否为邮箱
 * @param string $email 传入要检测的号码
 * @returns {boolean}  是传回true不是传回false
 */
function isEmail($email){
    var $emailzz=/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
    if($emailzz.test($email)){
        return true;
    }else {
        return false;
    }
}
/**
 * 图片预览
 * @param string $id 文件所在的input框的id
 * @param string $show 文件预览所在的id
 * @param int $width   文件预览宽度
 * @param int $height  文件预览高度
 */
function showImages($id,$show,$width,$height,$style){
    var $x;
    var $file;
    $show.empty();
    for(var b=0;b<$id.length;b++){
        $x=$id.eq(b).get(0).files;
        for(var a=0;a<$x.length;a++){
            $file=new FileReader;
            $file.readAsDataURL($x[a]);
            $file.onloadend=function(){
                if($width&&$height){
                    $show.append('<img src="'+this.result+'" width="'+$width+'" height="'+$height+'" style="'+$style+'"/>') ;
                }else if(!$width){
                    $show.append('<img src="'+this.result+'" height="'+$height+'" style="'+$style+'"/>');
                }else if(!$height){
                    $show.append('<img src="'+this.result+'" width="'+$width+'" style="'+$style+'"/>');
                }else{
                    $show.append('<img src="'+this.result+'" style="'+$style+'"/>');
                }
            }
        }
    }
}
/**
 * 检查密码是否可用
 * @param  string $pwd  要验证的密码
 * @returns {boolean}
 */
function ispwd($pwd) {
    var $zimuzz = /[a-zA-Z]+/;
    var $shuzi  = /[0-9]+/;
    if($zimuzz.test($pwd)&&$shuzi.test($pwd)){
        return true;
    }else {
        return false;
    }
}
/**
 * 检查是否为身份证
 * @param string $idcard 要检查的字符串
 * @returns {boolean}
 */
function isIdcard($idcard) {
    var $idcardzz = /^[0-9]{17}[0-9X]{1}$/;
    if($idcardzz.test($idcard)){
        return true;
    }else {
        return false;
    }
}
/**
 * 将ajax返回的数据转化成image
 * @param data：数据
 * @param width：宽
 * @param height：高
 * @param url：url地址
 * @returns {string}
 */
function strToImages(data,url,width,height) {
    var str = '';
    if(!width){
        width = '50';
    }
    if(!height){
        height = '50';
    }
    if(url){
        if(data){
            str = '<img src="'+url+'/'+data+'" width="'+width+'" height="'+height+'"/>';
        }else{
           str = '';
        }
    }else{
        if(data){
            str = '<img src="'+data+'" width="'+width+'" height="'+height+'"/>'
        } else{
            str = '';
        }
    }
    return str;
}
function arrayToImages(data,url,width,height) {
    var str = '';
    if(!data){
        return '';
    }
    if(!width){
        width = '50';
    }
    if(!height){
        height = '50';
    }
    if(data.length>=1){
        $.each(data,function (i,v) {
            str +=strToImages(v,url,width,height);
        });
        return str;
    }else {
        return '';
    }
}

/**
 * 将ajax返回的数据转化成str
 */
function toStr(data) {
    var str = '';
    if(data){
        str = data;
    }
    return str;
}

/**
 * 将数据转化成a标签
 * @param data
 * @returns {string}
 */
function toA(data) {
    var str = '';
    if(data){
        str = '<a href="'+data+'" target="_blank"></a>';
    }
    return str;
}
function getCheckbox($id) {
    var $array = new Array();
    $.each($id,function (i,v) {
        if($(v).prop('checked')){
            $array.push($(v).val())
        }
    })
    return $array;
}
/**
 *
 * @param $id
 * @param $url
 * @param $showBranch
 * @param $showThree_level
 * @param $urllevel
 */
function getBranch($id,$url,$showBranch,$showThree_level,$urllevel) {
    $.post($url,{id:$id},function (data) {
        if(data.code==200){
            $showBranch.empty();
            var $str = '';
            $.each(data.data,function (i,v) {
                $str +='<option value="'+v.id+'">'+v.branch_name+'</option>';
            });
            $showBranch.append($str);
        }else{
            layer.msg(data.msg);
        };
        var $sid = $showBranch.val();
        getThree_level($sid,$urllevel,$showThree_level);
    });
};
/**
 *
 * @param $id
 * @param $url
 * @param $showThree_level
 */
function getThree_level($id,$url,$showThree_level) {
    $.post($url,{id:$id},function (data) {
        if(data.code==200){
            $showThree_level.empty();
            var $str = '';
            $.each(data.data,function (i,v) {
                $str +='<option value="'+v.id+'">'+v.three_level_name+'</option>';
            });
            $showThree_level.append($str);
        }else{
            layer.msg(data.msg);
        }
    });
}
function getLaypage() {
    var $limit = $(".layui-laypage-limits select").val();
    var $page  = $(".layui-laypage-curr").children('em').eq(1).text();
    return {limit:$limit,page:$page};
}
function checkIsTrue($id) {
    if($id.prop('checked')){
        $("[type=checkbox]").prop('checked',true);
    }else{
        $("[type=checkbox]").prop('checked',false);
    }
}